package com.zhen.Utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static JwtUtils jwtUtils;
    private static String Key="zhenzhencao";
//    生成令牌
    public static String settoken(Map<String,Object> map){
        String jwt= Jwts.builder()
                .setClaims(map)
                .signWith(SignatureAlgorithm.HS256,Key)
                .setExpiration(new Date(System.currentTimeMillis()+12*3600*1000))
                .compact();
        System.out.println(jwt);
        return jwt;
    }
    //解析令牌
    public static Claims jietoken(String jwt){
        Claims claims=Jwts.parser()
                .setSigningKey(Key)
                .parseClaimsJws(jwt)
                .getBody();
        return claims;
    }
}
